//
//  HLTNetWorkingtool.m
//  huiliantong
//
//  Created by hlt on 15/8/13.
//  Copyright (c) 2015年 hlt. All rights reserved.
//

#import "HLTNetWorkingtool.h"
#import "AFNetworking.h"

@implementation HLTNetWorkingtool







//获取首页的广告图片
+(void) gethomearydata:(NSString *) url success:(void (^)(NSArray *ary))success faliure:(void(^)(NSString *error))faliure
{
    url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
        //获取前四家商铺的图片展示
        AFHTTPRequestOperationManager *m1 = [[AFHTTPRequestOperationManager alloc] init];
        
        // AFHTTPResponseSerializer不使用解析，即返回的为NSData类型数据，如果使用AFXMLParserResponseSerializer 解析会比较麻烦，所以会在后面使用第三方的XML解析(XMLReader)
        m1.responseSerializer = [AFHTTPResponseSerializer serializer];
    
        AFHTTPRequestOperation *op1 = [m1 GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
                                       {
                                          
                                           
                                           //将XML数据转换为我们需要的字典
                                           NSDictionary *dic = [userstool getxmldict:responseObject];
                                           NSLog(@"%@",dic[@"RtnMsg"]);
                                           
                                           if (![dic[@"RtnCode"] isEqual:@"0"]) {
                                               //调用3DES解密数据，如果已经获取过密钥，就用获取的密钥解密，否则使用初始密钥解密
                                               NSDictionary *dicc=[userstool getjiemidict:dic[@"RtnMsg"] jiemifangshi:NO];
                                               
                                               NSArray *arr1 = dicc[@"List_Item"];
                                              //解析成功后返回数组
                                              success(arr1);
                                               NSLog(@"%@",dicc);
                                               
                                           }
                                           else
                                           {
                                               //请求失败时调用这个使用初始密钥解密
                                               NSString *jsonkey=[Set3Des TripleDES:dic[@"RtnMsg"] deskey:kxhtkey encryptOrDecrypt:kCCDecrypt];
                                               NSLog(@"%@",jsonkey);
                                               faliure(jsonkey);
                                               UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"请求滚动广告失败"   message:jsonkey delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
                                               [alert show];
                                           }
                                         
                                       } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                           faliure(error.debugDescription);
                                           UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"请求滚动广告失败"   message:@"请检查网络" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
                                           [alert show];
                                           
                                       }];
        [op1 start];
    
    
    

}





+(void) getary:(NSString *)url success:(void (^)(NSArray *ary))success faliure:(void(^)(NSString *error))faliure
{
    
    url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    
    //获取列表
    AFHTTPRequestOperationManager *m1 = [[AFHTTPRequestOperationManager alloc] init];
    
    AFHTTPRequestOperation *op1 = [m1 GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
                                   {
                                       NSString *html = operation.responseString;
                                       NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
                                       NSArray *ary=[NSJSONSerialization  JSONObjectWithData:data options:0 error:nil];
                                       NSLog(@"获取到的数据为：%@",ary);
                                       success(ary);
                                       
                                   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                       faliure(error.debugDescription);
//                                       UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"请求数据失败"   message:@"请检查网络" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
//                                       [alert show];
                                   }];
    [op1 start];

    
    
}




+(void) getdic:(NSString *)url success:(void (^)(NSDictionary *ary))success faliure:(void(^)(NSString *error))faliure
{
    url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    //获取数据字典
    AFHTTPRequestOperationManager *m1 = [[AFHTTPRequestOperationManager alloc] init];
    
    AFHTTPRequestOperation *op1 = [m1 GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
                                   {
                                       NSString *html = operation.responseString;
                                       NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
                                       NSDictionary *ary=[NSJSONSerialization  JSONObjectWithData:data options:0 error:nil];
                                       NSLog(@"获取到的数据为：%@",ary);
                                       success(ary);
                                       
                                       
                                       
                                   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                       faliure(error.debugDescription);
//                                       UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"请求数据失败"   message:@"请检查网络" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
//                                       [alert show];
                                       
                                   }];
    [op1 start];
    
    
    
}












//获取首页的分类按钮图片
-(NSArray *) gethomemenu
{
    
    NSArray *aa=[NSArray new];
    return aa;
    
}

//获取推荐商铺列表信息
+(void) getyouhuilist:(NSString *)url success:(void (^)(NSMutableArray *ary))success faliure:(void(^)(NSString *error))faliure
{
    
    
     url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
  
    //获取推荐商铺列表
    AFHTTPRequestOperationManager *m1 = [[AFHTTPRequestOperationManager alloc] init];
    
    AFHTTPRequestOperation *op1 = [m1 GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
                                   {
                                       NSString *html = operation.responseString;
                                       NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
                                       NSMutableArray *ary=[NSJSONSerialization  JSONObjectWithData:data options:0 error:nil];
                                       NSLog(@"获取到的数据为：%@",ary);
                                       success(ary);
                                       
                                       
                                       
                                   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                       faliure(error.debugDescription);
                                       UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"请求失败"   message:@"请检查网络" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
                                       [alert show];
                                       
                                   }];
    [op1 start];
    
    
    
    
    
}





//获取周边商铺列表信息
+(void) getzhoubianlist:(NSString *)url success:(void (^)(NSMutableArray *ary))success faliure:(void(^)(NSString *error))faliure
{
    
    
    url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    
    //获取周边商铺列表
    AFHTTPRequestOperationManager *m1 = [[AFHTTPRequestOperationManager alloc] init];
    
    AFHTTPRequestOperation *op1 = [m1 GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
                                   {
                                       NSString *html = operation.responseString;
                                       NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
                                       NSDictionary *dic=[NSJSONSerialization  JSONObjectWithData:data options:0 error:nil];
                                       NSLog(@"获取到的数据为：%@",dic);
                                       
                                       NSMutableArray *ary=dic[@"list"];
                                       success(ary);
                                       
                                       
                                       
                                   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                       faliure(error.debugDescription);
                                       UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"请求失败"   message:@"请检查网络" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
                                       [alert show];
                                       
                                   }];
    [op1 start];
    
    
    
    
    
}











@end
